package com.chinasofti.treemap;

import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Demo02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一行字符串");
        String str = sc.nextLine();
        TreeMap<Character ,Integer> treeMap = new TreeMap<>();
        char [] chars = str.toCharArray();
        for(char c : chars){
            Integer i = treeMap.get(c);
            if (i == null){
                treeMap.put(c,1);
            }else {
                i++;
                treeMap.put(c,i);
            }
        }
        StringBuilder stringBuilder = new StringBuilder();
        Set<Character> set = treeMap.keySet();
        for (Character character : set){
            Integer values = treeMap.get(character);
            stringBuilder.append(character).append("(").append(values).append(")");
        }
        System.out.println(stringBuilder);
    }
}
